import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description: 牛客网: DP30 买卖股票的最好时机(一)
 * <a href="https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb?tpId=230&tqId=39767&ru=/exam/oj">...</a>
 * User: DELL
 * Date: 2023-08-23
 * Time: 22:23
 */
public class Main {
    /**
     * 解题思路:
     * 首先定义一个变量 maxProfit 用来记录最大利润,其次定义一个变量 min
     * 用来记录遍历到的最小值,然后从第二个元素开始遍历,
     * 若 arr[i] <= min  --- min = arr[i]
     * 若 arr[i] > min   --- maxProfit = Math.max(maxProfit,arr[i]-min)
     * 就这样子遍历数组一遍即可.
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        if (n <= 1) {
            System.out.println(0);
            return;
        }
        int min = arr[0];
        int maxProfit = 0;
        for (int i = 1; i < n; i++) {
            if (arr[i] <= min) {
                min = arr[i];
            } else {
                maxProfit = Math.max(maxProfit,arr[i]-min);
            }
        }
        System.out.println(maxProfit);
    }
}
